<template>
  <div class="app-container teacher-form-container">
    <div v-if="opt != 'add'">
      <el-descriptions title="">
        <el-descriptions-item label="企业名称">
          <el-tag style="margin-top: -5px;margin-left: 15px" size="medium">{{
              form.enterpriseName
            }}</el-tag>
<!--          <el-button style="margin-left: 10px;" v-if="form.businessStatusUser==adminuser && form.businessStatus==null || form.businessStatus==2" type="danger"  size="mini"  @click.stop="handleContract(form)">审 核</el-button>-->
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <el-tabs
      v-model="activeName"
      @tab-click="handleClick"
      class="operate-tabs"
    >
      <el-tab-pane label="商机信息" name="first">
        <div class="tab-content-scrollable">
          <el-form ref="form" :model="form" :rules="rules" label-width="150px">
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="商机名称"
                  prop="businessName"
                  label-width="110px"
                >
                <!-- :disabled="this.form.businessStatus==0||1||2" -->
                  <el-input
                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="form.businessName"
                    placeholder="请输入商机名称"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="客户名称"
                  prop="enterpriseName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.enterpriseName"
                    placeholder="请选择客户"
                    @focus="enterprise"
                    :readonly="readonly"
                    :disabled="opt === 'edit'"
                  />
                </el-form-item>
                <!-- &&this.form.businessStatus!==3 -->
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="创建时间"
                  prop="creationTime"
                  label-width="110px"
                >
                  <el-input v-model="form.creationTime" disabled="disabled" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="商机类型"
                  prop="businessType"
                  label-width="110px"
                >
                  <el-select
                    v-model="form.businessType"
                    placeholder="请选择商机类型"
                    style="width: 100%"
                  >
                    <el-option

                      v-for="dict in dict.type.business_classify"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="商机来源"
                  prop="businessSource"
                  label-width="110px"
                >
                  <el-select
                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="form.businessSource"
                    placeholder="请选择商机来源"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="dict in dict.type.business_source"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="商机阶段"
                  prop="businessState"
                  label-width="110px"
                >
                  <el-select
                    v-model="form.businessState"
                    placeholder="请选择商机阶段"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="dict in dict.type.business_state"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="联系人姓名"
                  prop="contacts"
                  label-width="110px"
                >
                  <el-input
                  :disabled="this.form.businessStatus!='3'"
                    v-model="form.contacts"
                    placeholder="请输入联系人姓名"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="联系人电话"
                  prop="telephone"
                  label-width="110px"
                >
                  <el-input
                  :disabled="this.form.businessStatus!='3'"
                    v-model="form.telephone"
                    placeholder="请输入联系人电话"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="联系人职位"
                  prop="position"
                  label-width="110px"
                >
                  <el-input
                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="form.position"
                    placeholder="请输入联系人职位"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="商机提供人"
                  prop="businessProvider"
                  label-width="110px"
                >
                  <el-input
                    :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="form.businessProvider"
                    placeholder="请输入商机提供人"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="提供人电话"
                  prop="businessRoviderNum"
                  label-width="110px"
                >
                  <el-input
                    :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="form.businessRoviderNum"
                    placeholder="请输入提供人电话"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="预计成交时间"
                  prop="expectedDate"
                  label-width="110px"
                >
                  <el-date-picker
                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    clearable
                    v-model="form.expectedDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    :picker-options="{ disabledDate: dateOptions }"
                    placeholder="请选择预计成交日期"
                    :editable="false"
                    style="width: 100%"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
<!--            <el-col :span="8" style="height: 55px">-->
<!--              <el-form-item-->
<!--                label="跟单阶段"-->
<!--                prop="trackingStage"-->
<!--                label-width="110px"-->
<!--              >-->
<!--                <el-select-->
<!--                :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"-->
<!--                  v-model="form.trackingStage"-->
<!--                  placeholder="请选择跟单阶段"-->
<!--                  style="width: 100%"-->
<!--                >-->
<!--                  <el-option-->
<!--                    v-for="dict in dict.type.tracking_stage"-->
<!--                    :key="dict.value"-->
<!--                    :label="dict.label"-->
<!--                    :value="dict.value"-->
<!--                  ></el-option>-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="创建人"
                  prop="creationName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.creationNickName"
                    placeholder="请输入创建人"
                    disabled="disabled"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="开发经理"
                  prop="developmentManager"
                  label-width="110px"
                >
                  <el-input
                    v-model="developmentManagerDisplay"
                    placeholder="请输入开发经理"
                    @focus="userShow(2)"
                    :readonly="readonly"
                    :disabled="isOpt"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="业务经理"
                  prop="businessManager"
                  label-width="110px"
                >
                  <el-input
                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="businessManagerDisplay"
                    placeholder="请选择业务经理"
                    @focus="userShow(3)"
                    :readonly="readonly"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="协作人"
                  prop="collaboratorName"
                  label-width="110px"
                >
                  <el-input
                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="collaboratorDisplay"
                    placeholder="请选择协作人"
                    @focus="userShow(4)"
                    :readonly="readonly"
                  />
                </el-form-item>
              </el-col>
<!--              <el-col :span="8" style="height: 55px">-->
<!--                <el-form-item-->
<!--                  label="审核人"-->
<!--                  prop="strName"-->
<!--                  label-width="110px"-->
<!--                >-->
<!--                  <el-input-->
<!--                  :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"-->
<!--                    v-model="strManagerDisplay"-->
<!--                    placeholder="请选择审核人"-->
<!--                    @focus="userShow(5)"-->
<!--                    :readonly="readonly"-->
<!--                  />-->
<!--                </el-form-item>-->
<!--              </el-col>-->
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="客户类型"
                  prop="customerType"
                  label-width="110px"
                >
                  <el-select
                    :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    v-model="form.customerType"
                    placeholder="请选择客户类型"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="dict in dict.type.customer_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 在最后一个 el-row 后添加新的备注行 -->
            <el-row>
              <el-col :span="16" style="height: 92px">
                <el-form-item
                  label="备注"
                  prop="remark"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.remark"
                    type="textarea"
                    :rows="3"
                    placeholder="请输入备注内容"
                    :disabled="this.form.businessStatus==0||this.form.businessStatus==1||this.form.businessStatus==2"
                    maxlength="500"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
                          <el-col :span="16" style="height: 55px">
                            <el-form-item label="附件" label-width="110px">
                              <file-view
                                :type="fileType"
                                :businessId="businessId"
                                :businessCode="businessCode"
                                @change="getFile"
                              ></file-view>
                            </el-form-item>
                          </el-col>
            </el-row>
          </el-form>
        </div>
        <div style="text-align: center; margin-top: 50px">
          <el-button type="primary" @click="submitFormOnce" v-if="isTwoSave"
            >连续新增</el-button
          >
<!--          <el-button type="primary" v-if="this.form.businessStatus!=0&&this.form.businessStatus!=1&&this.form.businessStatus!=2" @click="submitFormAll">提 交</el-button>-->
          <el-button type="primary" v-if="this.form.businessStatus!=0&&this.form.businessStatus!=1&&this.form.businessStatus!=2" @click="submitForm">保 存</el-button>
          <el-button type="primary" v-if="this.form.businessStatus==0 || this.form.businessStatus==1 || this.form.businessStatus==2 " @click="updateForm">变 更</el-button>
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="跟进记录"
        name="second"
        :disabled="isSwitch"
        v-if="opt !== 'add'"
      >
        <div>
          <el-tabs v-model="recordsActiveTab" type="card" class="records-tabs" @tab-click="handleRecordsTabClick">
            <el-tab-pane label="商机记录" name="business">
              <BusinessRecords
                :key="new Date().getTime()"
                :bId="bId!=null && bId!=''? bId : newBId"
                :businessStatus="form.businessStatus"
                :strNickName="form.strNickName"
                v-if="recordsActiveTab === 'business'"
              ></BusinessRecords>
            </el-tab-pane>
            <el-tab-pane label="客户记录" name="enterprise">
              <EnterpriseRecords
                :bId="enterpriseId"
                :is-add="false"
                :enterpriseId="form.enterpriseId"
                :enterpriseName="enterpriseName"
                :contacts="form.contacts"
                :telephone="form.telephone"
                v-if="recordsActiveTab === 'enterprise'"
              ></EnterpriseRecords>
            </el-tab-pane>
            <el-tab-pane label="线索记录" name="electric">
              <ElectricRecords
                :is-add="false"
                :bId="form.enterpriseId"
                v-if="recordsActiveTab === 'electric'"
              ></ElectricRecords>
            </el-tab-pane>
            <el-tab-pane label="公海记录" name="seas">
              <SeasRecords
                :is-add="false"
                :bId="form.enterpriseId"
                v-if="recordsActiveTab === 'seas'"
              ></SeasRecords>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div style="text-align: center; margin-top: 50px">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="报价信息"
        name="third"
        :disabled="isSwitch"
        v-if="opt !== 'add'"
      >
        <div style="text-align: center">
          <el-row :gutter="10" class="mb8" >
            <el-col :span="1.5">
              <el-button
                v-if="rowList.businessStatus==1"
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAddQuotation"
                >新增</el-button
              >
            </el-col>
          </el-row>
          <el-table
            v-loading="loading"
            style="width: 100%"
            :data="quotationInfoList"
          >
            <el-table-column label="序" type="index" :index="indexMethod" width="35"/>
            <el-table-column
              label="审核状态"
              align="center"
              prop="approvalResults"
              width="100"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.approvalResults === '同意'" style="color: green;">{{ scope.row.approvalResults }}</span>
                <span v-else-if="scope.row.approvalResults === '不同意'" style="color: red;">{{ scope.row.approvalResults }}</span>
                <span v-else>未审核</span>
              </template>
            </el-table-column>
            <el-table-column label="报价时间" align="center" prop="operateTime" width="85"
                             :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.operateTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="报价人"
              align="center"
              prop="operateName"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="客户名称"
              align="center"
              prop="companyName"
              :show-overflow-tooltip="true"
            />
            <el-table-column label="商机名称" align="center" prop="businessName" :show-overflow-tooltip="true"  width="80" />
            <el-table-colum label="预成交金额" align="center" prop="transactionAmount"
                             :show-overflow-tooltip="true"  width="80">
              <template slot-scope="scope">
                <span>{{scope.row.transactionAmount}}万元</span>
              </template>
            </el-table-colum>
            <el-table-column label="预成交时间" align="center" prop="transactionTime" width="85"
                             :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.transactionTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="版本"
              align="center"
              prop="version"
              :show-overflow-tooltip="true"
            />
            <el-table-column label="报价单附件" align="center" prop="uploadFile">
              <template slot-scope="scope">
                <el-button v-if="scope.row.url != null && scope.row.url != ''" @click="handlePictureCardPreview(scope.row.uploadFile, businessCode)" size="small"
                           type="text">附件</el-button>
                <el-button size="small" v-else type="text">无附件</el-button>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              :show-overflow-tooltip="true"
              width="80"
            >
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.isSubmit === '0'"
                  icon="el-icon-edit"
                  size="mini"
                  type="text"
                  @click="handleEditQuotation(scope.row)"
                  title="编辑"
                ></el-button>
                <el-button
                  icon="el-icon-view"
                  size="mini"
                  type="text"
                  v-if="scope.row.isSubmit === '1'"
                  @click="handleViewQuotation(scope.row)"
                  title="查看"
                ></el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  v-if="scope.row.isSubmit === '0'"
                  @click="handleDeleteQuotation(scope.row)"
                  title="删除"
                ></el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total3 > 0"
            :total="total3"
            :page.sync="queryParamsQuotation.pageNum"
            :limit.sync="queryParamsQuotation.pageSize"
            @pagination="getQuotation"
          />
        </div>
        <div style="text-align: center; margin-top: 50px">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="合同信息"
        name="four"
        :disabled="isSwitch"
        v-if="opt !== 'add'"
      >
        <div >
          <IndexPage
          :enterprise-name="this.enterpriseName"
          :enterprise-id="enterpriseId"
          :businessStatus="rowList.businessStatus"
          :businessId='rowList.businessId'
          :grandsonClass="'business'"
          ></IndexPage>
          <!-- <BusinessRecords
            :key="new Date().getTime()"
            :bId="bId"
          ></BusinessRecords> -->
        </div>
        <div style="text-align: center; margin-top: 50px">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
    </el-tabs>
    <select-user
      ref="select"
      :type="userType"
      :sign="sign"
      :userId="selectedUserId"
      @ok="selectUser"
    ></select-user>
    <SelectRoleUser
      ref="selectRole"
      :type="userType"
      :sign="newSign"
      :menuId="menuId"
      @ok="selectRoleUser"
    >
    </SelectRoleUser>
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-tabs v-model="activeNewName" @tab-click="handleNewClick" type="card">
        <el-tab-pane label="客户" name="one">
          <el-row>
            <el-col :span="24">
              <el-form
                :model="queryEnterpriseParams"
                ref="queryFormEnterprise"
                size="small"
                :inline="true"
                v-show="showSearch"
                label-width="100px"
              >
                <el-form-item label="企业名称" prop="enterpriseName">
                  <el-input
                    v-model="queryEnterpriseParams.enterpriseName"
                    placeholder="请输入企业名称"
                    clearable
                    @keyup.enter.native="handleQueryEnterprise"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQueryEnterprise"
                    >搜索</el-button
                  >
                  <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQueryEnterprise"
                    >重置</el-button
                  >
                  <el-button
                    type="primary"
                    size="mini"
                    @click="saveSelectEnterprise"
                    >确定</el-button
                  >
                </el-form-item>
              </el-form>
              <el-table
                ref="tableEnterprise"
                v-loading="loading"
                style="width: 100%"
                @selection-change="handleSelectionChangeEnterprise"
                :data="infoList"
              >
                <el-table-column type="selection" width="45" align="center" />
                <el-table-column
                  label="企业名称"
                  align="center"
                  prop="enterpriseName"
                />
                <el-table-column
                  label="联系人"
                  align="center"
                  prop="contacts"
                />
                <el-table-column
                  label="联系电话"
                  align="center"
                  prop="telephone"
                  show-overflow-tooltip="true"
                />
              </el-table>
              <pagination
                v-show="total1 > 0"
                :total="total1"
                :page.sync="queryEnterpriseParams.pageNum"
                :limit.sync="queryEnterpriseParams.pageSize"
                @pagination="getEnterpriseList"
              />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="公海" name="two">
          <el-row>
            <el-col :span="24">
              <el-form
                :model="querySeasParams"
                ref="queryFormSeas"
                size="small"
                :inline="true"
                v-show="showSearch"
                label-width="100px"
              >
                <el-form-item label="企业名称" prop="enterpriseName">
                  <el-input
                    v-model="querySeasParams.enterpriseName"
                    placeholder="请输入企业名称"
                    clearable
                    @keyup.enter.native="handleQuerySeas"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuerySeas"
                    >搜索</el-button
                  >
                  <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuerySeas"
                    >重置</el-button
                  >
                  <el-button type="primary" size="mini" @click="saveSelectSeas"
                    >确定</el-button
                  >
                </el-form-item>
              </el-form>

              <el-table
                ref="tableSeas"
                v-loading="loading"
                :data="seasList"
                @selection-change="handleSelectionChangeSeas"
              >
                <el-table-column type="selection" width="45" align="center" />
                <el-table-column
                  label="企业名称"
                  align="center"
                  prop="enterpriseName"
                />
                <el-table-column
                  label="联系人"
                  align="center"
                  prop="contacts"
                />
                <el-table-column
                  label="联系电话"
                  align="center"
                  prop="telephone"
                />
              </el-table>
              <pagination
                v-show="total2 > 0"
                :total="total2"
                :page.sync="querySeasParams.pageNum"
                :limit.sync="querySeasParams.pageSize"
                @pagination="getSeasList"
              />
            </el-col>
          </el-row>
        </el-tab-pane>
        <!--          电销-->
        <el-tab-pane label="线索" name="three">
          <el-row>
            <el-col :span="24">
              <el-form
                :model="queryEleParams"
                ref="queryFormEle"
                size="small"
                :inline="true"
                v-show="showSearch"
                label-width="100px"
              >
                <el-form-item label="企业名称" prop="enterpriseName">
                  <el-input
                    v-model="queryEleParams.enterpriseName"
                    placeholder="请输入企业名称"
                    clearable
                    @keyup.enter.native="handleQueryEle"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQueryEle"
                  >搜索</el-button
                  >
                  <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQueryEle"
                  >重置</el-button
                  >
                  <el-button
                    type="primary"
                    size="mini"
                    @click="saveSelectEle"
                  >确定</el-button
                  >
                </el-form-item>
              </el-form>

              <el-table
                ref="tableEle"
                v-loading="loading"
                :data="eleList"
                @selection-change="handleSelectionChangeEle"
              >
                <el-table-column type="selection" width="45" align="center" />
                <el-table-column
                  label="企业名称"
                  align="center"
                  prop="enterpriseName"
                />
                <el-table-column
                  label="联系人"
                  align="center"
                  prop="contacts"
                />
                <el-table-column
                  label="联系电话"
                  align="center"
                  prop="telephone"
                />
              </el-table>
              <pagination
                v-show="total5 > 0"
                :total="total5"
                :page.sync="queryEleParams.pageNum"
                :limit.sync="queryEleParams.pageSize"
                @pagination="getEleList"
              />
            </el-col>
          </el-row>
        </el-tab-pane>
        <!--          电销结束-->
      </el-tabs
    ></el-dialog>
    <el-dialog
      :title="titleQuotation"
      :visible.sync="openQuotation"
      width="800px"
      append-to-body
    >
      <el-form
        ref="querForm"
        :model="querForm"
        :rules="rulesQuotation"
        label-width="120px"
      >
        <el-row>
<!--          <el-col :span="8" style="height: 55px">-->
<!--            <el-form-item-->
<!--              label="立项编号"-->
<!--              prop="approvalNumber"-->
<!--              label-width="80px"-->
<!--            >-->
<!--              <el-input-->
<!--                v-model="querForm.approvalNumber"-->
<!--                placeholder="请输入立项编号"-->
<!--                :disabled="disabled"-->
<!--                style="width: 260px"-->
<!--              />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="8" style="height: 55px">
            <el-form-item
              label="商机名称"
              prop="businessName"
              label-width="80px"
            >
              <el-input
                v-model="businessName"
                placeholder="请输入商机名称" disabled="true"
                style="width: 260px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="14" style="height: 55px">
            <el-form-item
              label="客户名称"
              prop="companyName"
              label-width="230px"
            >
              <el-input
                v-model="querForm.companyName"
                placeholder="请输入公司名称"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>-->
<!--          <el-col :span="8" style="height: 55px">-->
<!--            <el-form-item-->
<!--              label="认证机构"-->
<!--              prop="certificateAuthority"-->
<!--              label-width="80px"-->
<!--            >-->
<!--              <el-input-->
<!--                v-model="querForm.certificateAuthority"-->
<!--                placeholder="请输入认证机构"-->
<!--                :disabled="disabled"-->
<!--                style="width: 260px"-->
<!--              />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="14" style="height: 55px">-->
<!--            <el-form-item-->
<!--              label="员工人数"-->
<!--              prop="employeeNumber"-->
<!--              label-width="230px"-->
<!--            >-->
<!--              <el-input-->
<!--                v-model="querForm.employeeNumber"-->
<!--                placeholder="请输入员工人数"-->
<!--                :disabled="disabled"-->
<!--              />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-row>-->
<!--          <el-col :span="22" style="height: 55px">-->
<!--            <el-form-item label="地址" prop="address" label-width="80px">-->
<!--              <el-input v-model="querForm.address" disabled />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
        <el-row>
          <el-col :span="8" style="height: 55px">
            <el-form-item label="联系人" prop="contacts" label-width="80px">
              <el-input
                v-model="querForm.contacts"
                placeholder="请输入联系人"
                style="width: 260px"
                :disabled="disabled"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14" style="height: 55px">
            <el-form-item label="联系电话" prop="unit" label-width="230px">
              <el-input
                v-model="querForm.unit"
                placeholder="请输入联系电话"
                :disabled="disabled"
                style="width: 215px"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" style="height: 55px">
            <el-form-item label="报价时间" prop="operateTime" label-width="80px">
              <el-date-picker
                clearable
                v-model="querForm.operateTime"
                type="date"
                :disabled="disabled"
                value-format="yyyy-MM-dd"
                :picker-options="{ disabledDate: dateOptions }"
                placeholder="请选择报价时间"
                :editable="false"
                style="width: 260px"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="14" style="height: 55px">
            <el-form-item
              label="报价人"
              prop="operateName"
              label-width="230px"
            >
              <el-input
                v-model="this.$store.state.user.info.nickName"
                placeholder="请输入报价人"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" style="height: 55px">
            <el-form-item label="预成交时间" prop="transactionTime" label-width="80px">
              <el-date-picker
                clearable
                v-model="querForm.transactionTime"
                type="date"
                :disabled="disabled"
                value-format="yyyy-MM-dd"
                :picker-options="{ disabledDate: dateOptions }"
                placeholder="请选择预成交时间"
                :editable="false"
                style="width: 260px"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="14" style="height: 55px">
            <el-form-item
              label="预成交金额"
              prop="transactionAmount"
              label-width="230px"
            >
              <el-input
                v-model="querForm.transactionAmount"
                placeholder="请输入预成交金额"
                :disabled="disabled"
              >
                <template #append>万元</template></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22" style="height: 92px">
            <el-form-item
              label="售后服务"
              prop="afterService"
              label-width="80px"
            >
              <el-input
                v-model="querForm.afterService"
                type="textarea"
                :rows="3"
                placeholder=" 请输入售后服务内容"
                :disabled="disabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22" style="height: 92px">
            <el-form-item label="温馨提示" prop="tips" label-width="80px">
              <el-input
                v-model="querForm.tips"
                type="textarea"
                :rows="3"
                placeholder=" 请输入温馨提示内容"
                :disabled="disabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" style="height: 52px">
            <el-form-item label="审批人" prop="approvalName" label-width="80px">
              <el-input
                :value="querForm.approvalDisplayName || querForm.approvalName"
                placeholder="请输入审批人"
                @focus="userRoleShow()"
                :disabled="disabled"
                style="width: 260px"
                readonly
              />
            </el-form-item>
          </el-col>
          <el-col :span="14" style="height: 55px">
            <el-form-item
              label="版本"
              prop="version"
              label-width="230px"
            >
              <el-input
                v-model="querForm.version"
                placeholder="请输入版本号"
                :disabled="disabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22" style="height: 55px" v-if="openQuotation">
            <el-form-item label="报价单附件" label-width="110px">
              <file-view
                :type="fileType"
                :businessId="querForm.uploadFile"
                :businessCode="businessCode"
              ></file-view>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22" v-if="isShow" style="height: 52px">
            <el-form-item
              label="审批结果"
              prop="approvalResults"
              label-width="230px"
            >
              <el-radio-group
                v-model="querForm.approvalResults"
                style="margin-left: 40px"
                :disabled="result"
              >
                <el-radio label="同意"></el-radio>
                <el-radio label="不同意"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="isShow">
          <el-col :span="22">
            <el-form-item
              label="审批信息"
              prop="approvalInformation"
              label-width="80px"
            >
              <el-input
                v-model="querForm.approvalInformation"
                type="textarea"
                :autosize="{ minRows: 2, mxRows: 4 }"
                placeholder=" 请输入审批信息"
                :disabled="result"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-col :span="22" >
          <div style="text-align: center; margin-top: 80px;">
            <el-button type="primary" @click="submitFormQuotation" v-if="isSave"
            >提 交</el-button
            >
            <el-button type="primary" @click="twoSave" v-if="isTwoSave"
            >复 制</el-button
            >
            <el-button type="primary" @click="saveFormQuotation" v-if="isSave"
            >保 存</el-button
            >
            <!--        <el-button type="primary" @click="printPreview" v-if="isPrint"-->
            <!--          >打印预览</el-button-->

            <el-button @click="cancelQuotation">关 闭</el-button>
          </div>
        </el-col>
      </el-row>
    </el-dialog>
    <el-dialog
      title="选择产品"
      :visible.sync="openProduct"
      width="1000px"
      append-to-body
    >
      <el-row>
        <el-col>
          <el-form
            :model="queryContractProductParams"
            ref="queryContractForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
          >
            <el-form-item label="产品类别" prop="productType">
              <el-select
                v-model="queryContractProductParams.productType"
                placeholder="请选择产品类别"
                clearable
              >
                <el-option
                  v-for="dict in dict.type.product_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="产品编号" prop="productNo">
              <el-input
                v-model="queryContractProductParams.productNo"
                placeholder="请输入产品编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="产品名称" prop="productName">
              <el-input
                v-model="queryContractProductParams.productName"
                placeholder="请输入产品名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQueryProduct"
                >搜索</el-button
              >
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetQueryProduct"
                >重置</el-button
              >
              <el-button type="primary" size="mini" @click="saveContractProduct"
                >确定</el-button
              >
            </el-form-item>
          </el-form>
          <el-table
            v-loading="loading"
            :data="qualificationList"
            ref="tableProduct"
            @current-change="handleSelectionChangeContractProduct"
            row-key="id"
            highlight-current-row
          >
            <el-table-column
              label="序号"
              type="index"
              :index="indexProductMethod"
            />
            <el-table-column label="产品类别" align="center" prop="productType">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.product_type"
                  :value="scope.row.productType"
                />
              </template>
            </el-table-column>
            <el-table-column label="产品编号" align="center" prop="productNo" />
            <el-table-column
              label="产品名称"
              align="center"
              prop="productName"
            />
            <el-table-column label="费用" align="center" prop="productPrice" />
          </el-table>
          <pagination
            v-show="total2 > 0"
            :total="total2"
            :page.sync="queryContractProductParams.pageNum"
            :limit.sync="queryContractProductParams.pageSize"
            @pagination="getProductList"
          />
        </el-col>
      </el-row>
    </el-dialog>
    <!-- 审核弹框 -->
    <el-dialog
      :visible.sync="dialogVisibleshop"
      title="审核商机"
    >
      <el-form ref="shopform" :model="shopform" :rules="rules" class="forms">
        <el-form-item label="审核选择" prop="businessStatus">
          <el-radio-group v-model="shopform.businessStatus"  @change="remarkText">
            <el-radio :label="1" >审核通过</el-radio>
            <el-radio :label="0">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitContract('shopform')">确 定</el-button>
        <el-button @click="cancelContract">取 消</el-button>
      </div>
    </el-dialog>
    <!--    附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="UploadCode"></UploadFile>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInformation,
  getInformation,
  delInformation,
  addInformation,
  updateInformation,
} from "@/api/enterprise/information";
import { listElectric} from "@/api/electric/electric";
import { listSeas, getSeas } from "@/api/highSeas/seas";
import { listInfo, getInfo } from "@/api/enterprise/info";
import {
  operealistInfo,
  getQuotationInfo,
  delInfo,
  saveQuotationProductMessage,
  updateQuotationProductMessage,
  sysDeptInfo,
} from "@/api/enterprise/quotation";
import { listMessage,listManager } from "@/api/enterprise/message";

import FileView from "@/components/FileView/index";
import SelectUser from "../../system/role/selectUser.vue";
import SelectRoleUser from "../../system/role/selectUser.vue";
import { listType } from "@/api/maintype/type";
import Treeselect from "@riophae/vue-treeselect";
import Seas from "../seas/index";
import MainType from "@/components/MainType/index";
import BusinessRecords from "../../records/records.vue";
import EnterpriseRecords from "../info/records.vue";
import ElectricRecords from "../electric/records.vue";
import SeasRecords from "../seas/seasRecords.vue";
import IndexPage from "../../contract/index.vue";
import EnterpriseInfo from "../../enterprise/info/index.vue";
import { listPerson } from "@/api/enterprise/person";
import { getSupplierInfo } from "@/api/supplier/supplier";
import { listQualificationAll } from "@/api/qualificationInfo/qualification";
import { getElectric } from "@/api/electric/electric";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Template from "../../membertemplate/index.vue";
import UploadFile from "../../upload/index.vue";
export default {
  name: "BusinessManager",
  dicts: [
    "business_classify",
    "customer_industry",
    "business_state",
    "tracking_stage",
    "enterprise_records",
    "business_source",
    "product_type",
    "customer_type"
  ],
  components: {
    UploadFile,
    Template,
    Treeselect,
    SelectUser,
    FileView,
    EnterpriseInfo,
    BusinessRecords,
    EnterpriseRecords,
    ElectricRecords,
    SeasRecords,
    Seas,
    MainType,
    IndexPage,
    SelectRoleUser,
    Operate: () => import("./operate"),
  },
  props: {
    opt: {
      type: String,
      default: "",
    },
    seas: {
      type: String,
      default: "0",
    },
    id: {
      type: String,
      default: "",
    },
    newBId: {
      type: String,
      default: "",
    },
    obj: {
      type: Object,
      default: null,
    },
    rowList: {
      type: Object,
      default: null,
    },
    //序号
    index: {
      type: Number,
      default: 0,
    },
    uuid: {
      type: String,
      default: "",
    },
    businessName:{
      type: String,
      default: null,
    },
    businessId: {
      type: String,
      default: "",
    },
    businessProvider:{
      type: String,
      default: null,
    },
    phone:{
      type: String,
      default: null,
    },
    demander:{
      type: String,
      default: null,
    },
    demandPhone:{
      type: String,
      default: null,
    },
    isClick: {
      type: Boolean,
      default: "",
    },
    classId: {
      type: String,
      default: "",
    },
    enterpriseId: {
      type: String,
      default: "",
    },
    enterpriseName: {
      type: String,
      default: "",
    },
    business: {
      type: Object,
      default: null,
    },
    businessStatus:{
      type: String,
      default: null,
    },
  },
  data() {
    var developmentManager = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("开发经理不能为空"));
      }
      return callback();
    };
    var enterpriseName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("客户名称不能为空"));
      }
      return callback();
    };
    var classificationId = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("主分类不能为空"));
      }
      return callback();
    };
    return {
      shopform:{
        businessStatus:null,
        businessId:''
      },
      isOpt: false,
      dialogVisibleshop: false,
      isTree: false,
      seasTypeCode: "seas",
      readonly: true,
      isSwitch: true,
      bId: "",
      refreshKey: 0,
      //选显卡默认选中
      activeName: "first",
      activeNewName: "one",
      userType: "1",
      menuId: "2121",
      sign: "1",
      newSign: "2",
      //附件
      uploadId: null,
      UploadCode: '',
      //附件对话框
      openFileList: false,
      adminuser:null,//管理员
      // 遮罩层
      loading: true,
      // 选中数组
      eIds: [],
      sIds: [],
      sContacts: [],
      eContacts: [],
      sTeles: [],
      eTeles: [],
      eName: [],
      sName: [],
      yIds: [],
      yNames: [],
      kIds: [],
      kNames: [],
      eNames:[],
      eleIds: [],
      eleContacts: [],
      eleTeles: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      total5: 0,
      // 【请填写功能名称】表格数据
      informationList: [],
      infoList: [],
      seasList: [],
      eleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      fileType: 0,
      businessCode: "businessinfo",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        businessName: null,
        classificationId: null,
        enterpriseId: null,
        enterpriseName: null,
        businessState: null,
        businessType: null,
        businessSource: null,
        contacts: null,
        telephone: null,
        position: null,
        businessProvider: null,
        expectedDate: null,
        trackingStage: null,
        followPerson: null,
        followId: null,
        developmentId: null,
        transactionId: null,
        developmentManager: null,
        businessManager: null,
        collaboratorId: null,
        collaboratorName: null,
        strName:null,
        businessStatusUser:null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
      },
      // 表单参数
      form: {
        businessStatus:"3",
        creationTime: this.showDate(),
        classificationId:
          this.classId == ""
            ? "650c44e1-b575-4b62-9d54-1ba9d1e8abb7"
            : this.classId,
        creationName: this.$store.state.user.info.userName,
        creationNickName: this.$store.state.user.info.nickName,
        remark: null, // 添加备注字段
      },
      querForm:{

      },
      // 表单校验
      rules: {
        enterpriseName: [
          { required: true, validator: enterpriseName, trigger: "change" },
        ],
        businessName: [
          { required: true, message: "商机名称不能为空", trigger: "blur" },
          { max: 50, message: "商机名称长度不能超过50", trigger: "blur" },
        ],
        classificationId: [
          { required: true, validator: classificationId, trigger: "blur" },
        ],
        businessType: [
          { required: true, message: "商机类型不能为空", trigger: "change" },
        ],
        businessState: [
          { required: true, message: "商机阶段不能为空", trigger: "change" },
        ],
        businessSource: [
          { required: true, message: "商机来源不能为空", trigger: "change" },
        ],
        strName:[
          { required: true, message: "审核人不能为空", trigger: "change" },
        ],
        contacts: [
          { required: true, message: "联系人姓名不能为空", trigger: "blur" },
          { max: 25, message: "联系人姓名长度不能超过25", trigger: "blur" },
        ],
        position: [
          { max: 10, message: "联系人职位长度不能超过10", trigger: "blur" },
        ],
        expectedDate: [
          { required: true, message: "预计成交时间不能为空", trigger: "blur" },
        ],
        businessProvider: [
          { required: true, message: "商机提供人不能为空", trigger: "blur" },
          { max: 25, message: "商机提供人长度不能超过25", trigger: "blur" },
        ],
        trackingStage: [
          { required: true, message: "跟单阶段不能为空", trigger: "change" },
        ],
        industry: [
          { required: true, message: "所属行业不能为空", trigger: "blur" },
        ],
        developmentManager: [
          { required: true, validator: developmentManager, trigger: "change" },
        ],
        businessManager: [
          { required: true, message: "开发经理不能为空", trigger: "blur" },
          { max: 50, message: "开发经理长度不能超过50", trigger: "blur" },
        ],
        telephone: [
          { required: true, message: "联系人电话不能为空", trigger: "blur" },
          { max: 50, message: "联系人电话长度不能超过50", trigger: "blur" },
        ],
        remark: [
          { max: 500, message: "备注长度不能超过500个字符", trigger: "blur" }
        ],
      },

      businessId: null,
      optionData: null,
      querySeasParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        administrativeArea: null,
        enterpriseNature: null,
        industry: null,
        classificationId: null,
      },
      queryEleParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        administrativeArea: null,
        enterpriseNature: null,
        industry: null,
        classificationId: null,
      },
      queryContractProductParams: {
        pageNum: 1,
        pageSize: 5,
        approve: null,
        productType: null,
        productNo: null,
        productName: null,
        productStatus: null,
        classificationId: null,
      },
      queryEnterpriseParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        enterpriseSource: null,
        enterpriseAbbreviation: null,
        administrativeArea: null,
        legalRepresentative: null,
        establishmentDate: null,
        contractAmount: null,
        enterpriseLabel: null,
        registeredCapital: null,
        industry: null,
        contacts: null,
        telephone: null,
        bankName: null,
        taxId: null,
        developmentId: null,
        transactionId: null,
        developmentManager: null,
        businessManager: null,
        enterpriseAddress: null,
        businessScope: null,
        enterpriseNature: null,
        markAs: "1",
        belongTo: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        classificationId: null,
      },
      selectedUserId: "",
      queryParamsQuotation: {
        pageNum: 1,
        pageSize: 15,
        approvalNumber: null,
        businessId:null,
      },
      quotationInfoList: [],
      rowList: null,
      isDel: true,
      newBId: "",
      total3: 0,
      isSave: true,
      isPrint: false,
      isTwoSave: false,
      newBusinessId: "",
      customName: "",
      customId: "",
      liaison: "",
      telephoneNumber: "",
      defaultContact: null, // 默认联系人
      defaultPhone: null, // 默认电话
      tableData: [],
      isShow: false,
      qId: "",
      titleQuotation: "",
      openProduct: false,
      showIndex: 0,
      qualificationList: [],
      productNames: [],
      queryParamsMessage: {
        pageNum: 1,
        pageSize: 15,
        quotationId: null,
        systemType: null,
        fees: null,
        notes: null,
      },
      result: false,
      openQuotation: false,
      newEnterpriseAddress: null,
      newEnterpriseName: null,
      newTelephone: null,
      isSame: true,
      rulesQuotation: {
        approvalNumber: [
          { required: true, message: "立项编号不能为空", trigger: "blur" },
          { max: 36, message: "立项编号长度不能超过36个字符", trigger: "blur" },
        ],
        certificateAuthority: [
          { required: true, message: "认证机构不能为空", trigger: "change" },
          { max: 25, message: "认证机构长度不能超过25个字", trigger: "blur" },
        ],
        contacts: [
          { required: true, message: "请选择联系人", trigger: "change" },
        ],
        unit: [
          { required: true, message: "请选择联系电话", trigger: "change" },
        ],
        employeeNumber: [
          { required: true, message: "员工人数不能为空", trigger: "change" },
          { max: 10, message: "联系人长度不能超过10个字", trigger: "blur" },
          {
            pattern: /^[1-9]\d*$/,
            message: "请输入正确的员工人数",
            trigger: "blur",
          },
        ],
        customerDemand: [
          { required: true, message: "客户需求不能为空", trigger: "change" },
          { max: 25, message: "客户需求长度不能超过25个字", trigger: "blur" },
        ],
        quotationDescription: [
          { required: true, message: "报价说明不能为空", trigger: "blur" },
          {
            max: 1000,
            message: "报价说明长度不能超过1000个字",
            trigger: "blur",
          },
        ],
        paymentMethod: [
          { required: true, message: "付款方式不能为空", trigger: "blur" },
          {
            max: 1000,
            message: "付款方式长度不能超过1000个字",
            trigger: "blur",
          },
        ],
        afterService: [
          {
            max: 1000,
            message: "售后服务长度不能超过1000个字",
            trigger: "blur",
          },
        ],
        tips: [
          {
            max: 1000,
            message: "温馨提示长度不能超过1000个字",
            trigger: "blur",
          },
        ],
        approvalName: [
          { required: true, message: "请选择审批人", trigger: "change" },
        ],
        approvalInformation: [
          {
            max: 1000,
            message: "审批信息长度不能超过1000个字",
            trigger: "blur",
          },
        ],
        approvalResults: [
          { required: true, message: "审批结果不能为空", trigger: "blur" },
        ],
      },
      recordsActiveTab: "business",
    };
  },
  created() {
    this.adminuser=this.$store.state.user.info.userId
    this.listType();
    this.getEnterpriseList();
    this.getSeasList();
    this.getEleList();
    this.getQuotation();
    this.getProductList();
    console.log(typeof this.form.businessStatus,'this.form.businessStatus')
    if (this.opt == "add") {
      console.log("是否是新增")
      if (this.business !== null) {
        this.form = this.business;
      }
      this.form.businessStatus="3"
      // console.log(this.form.businessStatus,'this.opt');
      // console.log(this.form.businessStatus,'this.form.businessStatus=3');
      this.fileType = 0;
      this.isOpt = false;
      this.bId = this.uuid;
      if (this.businessId==='' || this.businessId === null){
        this.businessId = this.uuid;
        this.form.businessId = this.businessId;
        console.log("id为空")
      }else {
        this.form.businessId = this.businessId;
        console.log("id不为空",this.form.businessId)
      }
      this.isSwitch = this.isClick;
      if (this.businessProvider!=null && this.phone!=null){
  this.$set(this.form, 'businessProvider', this.businessProvider);
  this.$set(this.form, 'businessRoviderNum', this.phone);
}
if (this.demander!=null && this.demandPhone!=null){
  this.$set(this.form, 'contacts', this.demander);
  this.$set(this.form, 'telephone', this.demandPhone);
}
      this.form.enterpriseName=this.enterpriseName;


    }
    if (this.opt == "edit") {
      console.log(this.form.businessStatus,'this.form.businessStatus')
      this.queryParamsQuotation.businessId=this.rowList.businessId
      this.fileType = 1;
      this.businessId = this.id;
      this.bId = this.id;
      this.isOpt = true;
      this.isSwitch = this.isClick;
      this.querForm=this.rowList
      console.log(this.querForm,'rowlllll');
      console.log(this.newBId,'newBId');
      this.handleUpdate(this.id);
    }
    console.log(this.form,'this.form')
    if (this.enterpriseId != "" && this.enterpriseId != null) {
      this.form.enterpriseId = this.enterpriseId;
      this.form.enterpriseName = this.enterpriseName;
    }
    console.log(this.form.businessStatus,"这时候为多少")
  },
  methods: {
    cancelQuotation() {
      this.resetBaoJia();
      this.openQuotation = false;
      this.tableData = [];
    },
    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (
        S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4()
      );
    },
    //附件
    handlePictureCardPreview(id, code) {
      this.uploadId = id;
      this.UploadCode = code;
      this.openFileList = true;
    },
    //序号展示
    indexMethod(index) {
      return (this.queryParamsQuotation.pageNum - 1) * this.queryParamsQuotation.pageSize + index + 1;
    },
    async getContactsList(companyId) {
      console.log(companyId);
      const params = {
        enterpriseId: companyId,
        organizationId: this.$store.state.user.info.orgId,
      };
      const response = await listPerson(params);
      if (response && response.rows) {
        this.contactsList = response.rows;
        // 如果有默认联系人和电话，将其设置为第一个选项
        if (this.defaultContact && this.defaultPhone) {
          const defaultPerson = {
            id: "default",
            name: this.defaultContact,
            phone: this.defaultPhone,
          };
          // 检查默认联系人是否已存在于列表中
          const exists = this.contactsList.some(
            contact => contact.phone === this.defaultPhone
          );
          if (!exists) {
            this.contactsList.unshift(defaultPerson);
          }
        }
      }
    },
    // 取消按钮
    cancelContract() {
      this.dialogVisibleshop=false
    },
    //审核
    handleContract(row) {
      this.dialogVisibleshop=true
      this.shopform.businessStatus==null
      this.shopform.businessId=row.businessId
    },
    submitContract() {
      console.log(this.shopform.businessStatus,'this.shopform.businessStatus')
      if(this.shopform.businessStatus==null){
        this.$message.error('请选择审核意见')
      }else{
        updateInformation(this.shopform).then(res => {
          this.$message.success('审核成功')
          this.dialogVisibleshop=false
          this.shopform.businessStatus==null
          this.$emit("change");
        })
      }
    },
    handleAddQuotation() {
      // console.log(this.form.businessStatus,'businessStatusbusinessStatus');
      this.resetBaoJia();
      console.log(this.form,'数据')
      this.disabled = false;
      this.isDel = true;
      this.isSave = true;
      this.isPrint = false;
      this.isTwoSave = false;
      this.querForm.businessId = this.rowList.businessId;
      this.newBusinessId = this.rowList.businessId;
      this.querForm.companyName = this.rowList.enterpriseName;
      this.querForm.companyId = this.rowList.enterpriseId;
      this.querForm.contacts = this.rowList.contacts;
      this.querForm.unit = this.rowList.telephone;
      this.customName = this.rowList.enterpriseName;
      this.customId = this.rowList.enterpriseId;
      this.liaison = this.rowList.contacts;
      this.telephoneNumber = this.rowList.telephone;
      getInfo(this.customId).then(response => {
        if (
          response.data.enterpriseName == null ||
          response.data.enterpriseName === ""
        ) {
          getSeas(this.customId).then(response => {
            if (response.data === undefined) {
              getElectric(this.customId).then(response => {
                if (response.data === undefined) {
                  getSupplierInfo(this.customId).then(response => {
                    this.querForm.address = response.data.enterpriseAddress;
                  });
                } else {
                  this.querForm.address = response.data.enterpriseAddress;
                }
              });
            } else {
              this.querForm.address = response.data.enterpriseAddress;
            }
          });
        } else {
          this.querForm.address = response.data.enterpriseAddress;
        }
      });
      // 保存默认联系人和电话
      this.defaultContact = this.rowList.contacts;
      this.defaultPhone = this.rowList.telephone;
      // 获取联系人列表
      this.getContactsList(this.rowList.enterpriseId);
      // 设置默认联系人和电话
      this.querForm.contacts = this.rowList.contacts;
      this.querForm.unit = this.rowList.telephone;
      this.tableData = [];
      this.isShow = false;
      this.qId = this.guid();
      this.titleQuotation = "新增报价单信息";
      this.querForm.uploadFile=new Date().getTime();
      this.fileType=0;
      this.openQuotation = true;
      this.queryParamsQuotation.businessId = this.rowList.businessId;
      // this.form.businessStatus=this.rowList.businessStatus
      // console.log(this.form.businessStatus,'businessStatusbusinessStatus2222');
    },
    handleDeleteQuotation(row) {
      const ids = row.quotationId;
      this.$modal
        .confirm('是否确认删除立项编号为"' + row.approvalNumber + '"的数据项？')
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getQuotation();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleViewQuotation(row) {
      this.result = false;
      this.isPrint = false;
      this.isSave = true;
      const id = row.quotationId;
      this.fileType = 2;
      getQuotationInfo(id).then(response => {
        this.resetBaoJia();
        this.querForm = response.data;
        console.log(this.querForm.uploadFile, "this.querForm.uploadFile123")

        // 设置显示昵称
        this.querForm.approvalDisplayName =
          response.data.approvalNickName || response.data.approvalName;
        this.disabled = true;
        this.isDel = false;
        this.isSave = false;
        this.isShow = false;
        this.isTwoSave = false;

        if (this.querForm.approvalResults === "同意") {
          this.isPrint = true;
        }
        if (
          this.querForm.approvalResults != null &&
          this.querForm.approvalResults !== ""
        ) {
          this.result = true;
          this.isShow = true;
          this.isTwoSave = true;
        }
        if (
          this.querForm.approvalResults === "同意" ||
          this.querForm.approvalResults === "不同意"
        ) {
          this.isSave = false;
        }

        console.log(this.querForm.uploadFile, "this.querForm.uploadFile321")
        this.openQuotation = true;
      });
      // this.queryParamsMessage.quotationId = row.quotationId;
      // listMessage(this.queryParamsMessage).then(response => {
      //   this.tableData = response.rows;
      // });
    },
    // handleViewQuotation(row) {
    //   this.result = false;
    //   this.isPrint = false;
    //   this.isSave = true;
    //   const id = row.quotationId;
    //   this.fileType=2;
    //   getQuotationInfo(id).then(response => {
    //     this.resetBaoJia();
    //     this.querForm = response.data;
    //     console.log(this.querForm.uploadFile,"this.querForm.uploadFile123")
    //     // 设置显示昵称
    //     this.querForm.approvalDisplayName =
    //       response.data.approvalNickName || response.data.approvalName;
    //     this.disabled = true;
    //     this.isDel = false;
    //     this.isSave = false;
    //     this.isShow = false;
    //     this.isTwoSave = false;
    //     if (this.querForm.approvalResults === "同意") {
    //       this.isPrint = true;
    //     }
    //     if (
    //       this.querForm.approvalResults != null &&
    //       this.querForm.approvalResults !== ""
    //     ) {
    //       this.result = true;
    //       this.isShow = true;
    //       this.isTwoSave = true;
    //     }
    //     if (
    //       this.querForm.approvalResults === "同意" ||
    //       this.querForm.approvalResults === "不同意"
    //     ) {
    //       this.isSave = false;
    //     }
    //   });
    //   // this.queryParamsMessage.quotationId = row.quotationId;
    //   // listMessage(this.queryParamsMessage).then(response => {
    //   //   this.tableData = response.rows;
    //   // });
    //   console.log(this.querForm.uploadFile,"this.querForm.uploadFile321")
    //   this.openQuotation = true;
    // },
    selectRoleUser(userId, userName, phone, position, nickName) {
      // 使用普通对象先准备所有更新
      const updates = {
        approvalName: userName,
        approvalId: userId,
        approvalDisplayName: nickName || userName,
        approvalNickName: nickName,
      };

      // 一次性更新所有属性
      Object.keys(updates).forEach(key => {
        this.$set(this.querForm, key, updates[key]);
      });

      // 强制更新视图
      this.$forceUpdate();
    },
    handleEditQuotation(row) {
      // 重置表单
      this.resetBaoJia();
      // 设置按钮和表单状态
      this.disabled = false; // 启用表单编辑
      this.isDel = true; // 显示删除按钮
      this.isSave = true; // 显示保存按钮
      this.isPrint = false; // 隐藏打印按钮
      this.isTwoSave = false; // 隐藏复制按钮
      this.isShow = false; // 隐藏审批结果区域
      // 获取报价单详细信息
      const id = row.quotationId;
      // 获取报价单产品信息列表
      // this.queryParamsMessage.quotationId = id;
      // listMessage(this.queryParamsMessage).then(response => {
      //   this.tableData = response.rows;
      // });
      getQuotationInfo(id).then(response => {
        this.querForm = response.data;        // 设置显示昵称
        this.querForm.approvalDisplayName =
          response.data.approvalNickName || response.data.approvalName;
        console.log(this.querForm,'this.querForm1111');
        // 设置标题和打开弹窗
        this.fileType = 1;
        this.titleQuotation = "修改报价单信息";
        console.log(this.querForm,'this.querForm')
        this.openQuotation = true;
      });
    },
    getQuotation() {
      this.queryParamsQuotation.businessId = this.newBId;
      operealistInfo(this.queryParamsQuotation).then(response => {
        this.quotationInfoList = response.rows;
        this.total3 = response.total;
      });
    },
    handleSelectionChangeContractProduct(selection) {
      if (selection && selection.productName) {
        this.productNames = selection.productName;
      } else {
        this.productNames = null;
      }
    },
    getProductList() {
      this.loading = true;
      this.queryContractProductParams.productStatus = "已上架";
      listQualificationAll(this.queryContractProductParams).then(response => {
        this.qualificationList = response.rows;
        this.total2 = response.total;
        this.loading = false;
      });
    },
    submitFormQuotation() {
      this.$refs["querForm"].validate(valid => {
        if (!valid) {
          return;
        }
        // // 检查是否有产品信息
        // if (!this.tableData || this.tableData.length === 0) {
        //   this.$message.error("请至少添加一条产品信息！");
        //   return;
        // }
        // 检查所有产品信息是否完整
        const hasIncompleteProduct = this.tableData.some(
          item =>
            !item.systemType?.trim() ||
            !item.fees?.toString().trim() ||
            !item.notes?.trim()
        );
        if (hasIncompleteProduct) {
          this.$message.error("请完善所有报价单产品信息！");
          return;
        }
        // 确认提交
        this.$confirm("提交后不能再修改报价单信息，是否继续？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            // 准备提交数据
            const submitData = {
              ...this.querForm,
              isSubmit: "1", // 设置提交状态
              productMessageList: this.tableData,
            };

            // 如果是新增，添加quotationId
            if (!this.querForm.quotationId || !this.isSame) {
              submitData.quotationId = this.qId;
            }

            // 根据是否存在quotationId决定是新增还是修改
            const request =
              this.querForm.quotationId && this.isSame
                ? updateQuotationProductMessage(submitData)
                : saveQuotationProductMessage(submitData);

            // 发送请求并处理响应
            request
              .then(response => {
                this.$modal.msgSuccess(
                  this.querForm.quotationId && this.isSame ? "修改成功" : "新增成功"
                );
                this.handleSubmitSuccess();
              })
              .catch(error => {
                this.$modal.msgError(
                  "操作失败：" + (error.message || "未知错误")
                );
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消提交",
            });
          });
      });
    },
    // 提取成功处理逻辑为独立方法
    handleSubmitSuccess() {
      this.openQuotation = false;
      this.tableData = [];
      // this.getList();
      this.getQuotation();
    },
    //打印预览
    printPreview() {
      const id = this.form.quotationId;
      getQuotationInfo(id).then(response => {
        this.querForm = response.data;
        this.newApprovalNumber = this.form.approvalNumber;
        this.newCompanyName = this.form.companyName;
        this.newEmployeeNumber = this.form.employeeNumber;
        this.newAddress = this.form.address;
        this.newCertificateAuthority = this.form.certificateAuthority;
        this.newContacts = this.form.contacts;
        this.newPhone = this.form.unit;
        this.newCustomerDemand = this.form.customerDemand;
        this.newUnit = this.form.unit;
        this.newQuotationDescription = this.form.quotationDescription;
        this.newPaymentMethod = this.form.paymentMethod;
        this.newAfterService = this.form.afterService;
        this.newTips = this.form.tips;
      });
      this.queryParamsMessage.quotationId = id;
      listMessage(this.queryParamsMessage).then(response => {
        this.tableData = response.rows;
      });
      sysDeptInfo().then(response => {
        this.newEnterpriseAddress = response[0].address;
        this.newEnterpriseName = response[0].deptName;
        this.newTelephone = response[0].phone;
      });
      this.openPrint = true;
    },

    twoSave() {
      this.isTwoSave = false;
      this.isSave = true;
      this.isSame = false;
      this.disabled = false;
      this.isDel = true;
      this.isPrint = false;
      this.isShow = false;
      this.qId = this.guid();
      this.querForm.approvalNumber = null;
      this.querForm.approvalResults = null;
      this.querForm.approvalInformation = null;
    },
    delProductInfo(row) {
      this.tableData = this.tableData.filter(data => data.id !== row.id);
      if (row.number !== "" && row.number != null) {
        this.sum =
          parseInt(this.sum) + parseInt(this.tempSum) - parseInt(row.number);
      }
    },
    /** 保存按钮 */
    saveFormQuotation() {
      this.$refs["querForm"].validate(valid => {
        if (valid) {
          var tableList = this.tableData;
          // 先检查所有产品信息是否完整
          for (var i = 0; i < tableList.length; i++) {
            if (
              !tableList[i].systemType ||
              !tableList[i].fees ||
              !tableList[i].notes
            ) {
              this.$message.error("请完善报价单产品信息！");
              return; // 直接返回整个方法
            }
          }
          // 所有产品信息完整后，再进行保存操作
          if (this.querForm.quotationId != null && this.isSame) {
            this.querForm.isSubmit = "0"; // 设置保存状态
            this.querForm["productMessageList"] = this.tableData;
            const data = this.querForm;
            console.log(data,'data111');
            updateQuotationProductMessage(data).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openQuotation = false;
              this.tableData = [];
              // this.getList();
              this.getQuotation();
            });
          } else {
            this.querForm.quotationId = this.qId;
            this.querForm.isSubmit = "0"; // 设置保存状态
            this.querForm["productMessageList"] = this.tableData;
            const data = this.querForm;
            console.log(data,'data22');
            saveQuotationProductMessage(data).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openQuotation = false;
              this.tableData = [];
              // this.getList();
              this.getQuotation();

            });
          }
        }
      });
    },
    userRoleShow() {
      this.$refs.selectRole.show();
    },
    saveContractProduct() {
      if (!this.productNames) {
        this.$modal.msgError("请先选择产品！");
        return;
      }

      // 确保 showIndex 有效且 tableData 存在对应索引的数据
      if (!this.tableData || !this.tableData[this.showIndex - 1]) {
        this.$modal.msgError("产品选择出错，请重试！");
        this.openProduct = false;
        return;
      }

      // 检查产品是否已经存在于表格中
      const isProductExists = this.tableData.some((item, index) => {
        // 跳过当前正在编辑的行
        if (index === this.showIndex - 1) {
          return false;
        }
        return item.systemType === this.productNames.toString();
      });

      if (isProductExists) {
        this.$modal.msgError("该产品已经添加过，请选择其他产品！");
        return;
      }

      try {
        // 确保当前行数据存在
        if (!this.tableData[this.showIndex - 1]) {
          this.tableData[this.showIndex - 1] = {
            indexTwo: this.showIndex,
            id: this.guid(),
            quotationId: this.qId,
            systemType: "",
            fees: "",
            notes: "",
          };
        }

        // 更新产品信息
        this.$set(
          this.tableData[this.showIndex - 1],
          "systemType",
          this.productNames.toString()
        );

        this.openProduct = false;
      } catch (error) {
        console.error("保存产品信息时出错:", error);
        this.$modal.msgError("保存产品信息失败，请重试！");
      }
    },
    submitFormOnce() {
      this.fileType = 0;
      this.reset();
      this.refreshKey++;
      this.form.creationTime = this.showDate();
      this.form.classificationId =
        this.classId == ""
          ? "650c44e1-b575-4b62-9d54-1ba9d1e8abb7"
          : this.classId;
      this.form.creationName = this.$store.state.user.info.userName;
      this.uuid = this.guid();
      this.form.businessId = this.uuid;
      this.isOpt = false;
      this.businessId = this.form.businessId;
      this.bId = this.form.businessId;
      this.isSwitch = true;
      this.isTwoSave = false;
    },
    addProductInfo() {
      const tableList = this.tableData;

      // 检查是否有未完成的行
      const hasIncompleteRow = tableList.some(
        row =>
          !row.systemType?.trim() ||
          !row.fees?.toString().trim() ||
          !row.notes?.trim()
      );

      if (hasIncompleteRow) {
        this.$message.error("请先完善当前行数据！");
        return;
      }

      // 添加新行
      this.tableData.push({
        indexTwo: tableList.length + 1,
        id: this.guid(),
        quotationId: this.qId,
        systemType: "",
        fees: "",
        notes: "",
      });
    },
    selectProduct(index) {
      if (!this.tableData) {
        this.tableData = [];
      }

      this.showIndex = index;
      this.openProduct = true;

      // 重置选择状态
      this.$nextTick(() => {
        if (this.$refs.tableProduct) {
          this.$refs.tableProduct.setCurrentRow(null);
        }
        this.productNames = null;
      });
    },
    /** 搜索按钮操作 */
    handleQueryEnterprise() {
      this.queryEnterpriseParams.pageNum = 1;
      this.getEnterpriseList();
    },
    /** 重置按钮操作 */
    resetQueryEnterprise() {
      this.resetForm("queryFormEnterprise");
      this.handleQueryEnterprise();
    },
    /** 搜索按钮操作 */
    handleQuerySeas() {
      this.querySeasParams.pageNum = 1;
      this.getSeasList();
    },
    /** 搜索按钮操作 */
    handleQueryEle() {
      this.queryEleParams.pageNum = 1;
      this.getEleList();
    },
    getEleList() {
      this.loading = true;
      listElectric(this.queryEleParams).then(response => {
        this.eleList = response.rows;
        this.total5 = response.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQueryEle() {
      this.resetForm("queryFormEle");
      this.handleQueryEle();
    },
    /** 重置按钮操作 */
    resetQuerySeas() {
      this.resetForm("queryFormSeas");
      this.handleQuerySeas();
    },
    getEnterpriseList() {
      this.loading = true;
      listInfo(this.queryEnterpriseParams).then(response => {
        this.infoList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    getSeasList() {
      this.loading = true;
      listSeas(this.querySeasParams).then(response => {
        this.seasList = response.rows;
        this.total2 = response.total;
        this.loading = false;
      });
    },
    getFile(data) {
      console.log(JSON.stringify(data));
    },
    listType() {
      listType({ typeCode: "business" }).then(res => {
        this.optionData = res.data;
      });
    },
    beforeHandle() {
      if (3 == "no") {
        this.$message.error("请先保存商机基本信息！");
      } else {
      }
    },
    handleClick(tab, event) {
      if (tab.name == "first") {
      }
      if (tab.name == "second") {
      }
    },
    handleNewClick(tab, event) {
      if (tab.name == "one") {
        this.$refs.tableSeas.clearSelection(); // 清空所有选择
      }
      if (tab.name == "two") {
        this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
      }
    },
    userShow(type) {
      this.show = type;
      this.$refs.select.show();
    },
    // 取消按钮
    cancel() {
      this.$emit("change");
      this.form={}
    },
    // 表单重置
    reset() {
      this.form = {
        businessId: null,
        businessName: null,
        classificationId: null,
        enterpriseId: null,
        enterpriseName: null,
        businessState: null,
        businessType: null,
        businessSource: null,
        contacts: null,
        telephone: null,
        position: null,
        businessProvider: null,
        expectedDate: null,
        trackingStage: null,
        followPerson: null,
        followId: null,
        developmentId: null,
        transactionId: null,
        developmentManager: null,
        businessManager: null,
        collaboratorId: null,
        collaboratorName: null,
        strName: null,
        businessStatusUser:null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        delFlag: null,
        creationName: this.$store.state.user.info.userName,
        creationNickName: this.$store.state.user.info.nickName,
        remark: null, // 添加备注字段
        customerType:null,
        businessRoviderNum:null
      };
      this.resetForm("form");
    },
    resetBaoJia(){
      this.querForm = {
        quotationId: null,
        businessId: null,
        approvalNumber: null,
        companyId: null,
        companyName: null,
        employeeNumber: null,
        address: null,
        certificateAuthority: null,
        contacts: null,
        customerDemand: null,
        unit: null,
        quotationDescription: null,
        paymentMethod: null,
        afterService: null,
        tips: null,
        isSubmit: null,
        approvalId: null,
        approvalName: null,
        approvalResults: null,
        approvalInformation: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        version:null,
        transactionAmount:null,
        transactionTime:null,
        operateName:null,
        uploadFile:null,
      };
      this.resetForm("querForm");
      this.tableData = [];
      this.contactsList = [];
      this.defaultContact = null;
      this.defaultPhone = null;
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      this.reset();
      getInformation(id).then(response => {
        this.reset();
        this.form = response.data;
        // this.form.creationTime = this.formatterDate(this.form.creationTime);
      });
    },
    /** 提交按钮 */
    submitFormAll() {

      if (this.opt == "add" || this.opt == "edit") {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.opt == "add") {
              if (this.form.businessId == null) {
                this.form.businessId = this.uuid;
              }
              this.bId = this.form.businessId;
              this.business = null;
            }
            this.form.businessStatus=2
            updateInformation(this.form).then(response => {
              this.isSwitch = false;
              this.$modal.msgSuccess("提交成功");
              this.business = null;
              this.isTwoSave = true;
              this.$emit("change");
            });
          }
        });
      }
    },
    submitForm() {
      this.form.businessStatus=3
      if (this.opt == "add" || this.opt == "edit") {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.opt == "add") {
              if (this.form.businessId == null){
                this.form.businessId = this.uuid;
              }
              this.bId = this.form.businessId;
              this.business = null;
            }
            updateInformation(this.form).then(response => {
              this.isSwitch = false;
              this.$modal.msgSuccess("保存成功");
              this.business = null;
              this.isTwoSave = true;
            });
          }
        });
      }
    },
    updateForm(){
      updateInformation(this.form).then(response => {
        this.$modal.msgSuccess("变更成功");
      });
    },
    dateOptions(time) {
      return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
    },
    showDate() {
      var mydate = new Date();
      var str = "" + mydate.getFullYear() + "-";
      str +=
        mydate.getMonth() + 1 <= 9
          ? "0" + (mydate.getMonth() + 1) + "-"
          : mydate.getMonth() + 1 + "-";
      str += mydate.getDate() <= 9 ? "0" + mydate.getDate() : mydate.getDate();
      return str;
    },
    close() {
      this.open = false;
    },
    enterprise() {
      this.open = true;
    },
    selectUser(userId, userName, phone, position, nickName) {
      this.selectedUserId = userId;
      if(this.show=="2"){
        this.$set(this.form, "developmentManager", userName);
        this.$set(this.form, "developmentId", userId);
        this.$set(this.form, "developmentManagerNickName", nickName);
      }else if (this.show == "3") {
        this.$set(this.form, "businessManager", userName);
        this.$set(this.form, "businessManagerNickName", nickName);
        this.$set(this.form, "transactionId", userId);
      } else if (this.show == "4") {
        this.$set(this.form, "collaboratorName", userName);
        this.$set(this.form, "collaboratorNickName", nickName);
        this.$set(this.form, "collaboratorId", userId);
      }
      else if (this.show == "5") {
        this.$set(this.form, "strName", userName);
        this.$set(this.form, "strNickName", nickName);
        this.$set(this.form, "businessStatusUser", userId);
      }
    },
    handleSelectionChangeSeas(selection) {
      if (selection.length > 1) {
        this.$refs.tableSeas.clearSelection(); // 清空所有选择
        this.$refs.tableSeas.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.sIds = selection.map(item => item.enterpriseId);
        this.sName = selection.map(item => item.enterpriseName);
        this.sContacts = selection.map(item => item.contacts);
        this.sTeles = selection.map(item => item.telephone);
        this.kIds = selection.map(item => item.developManager);
        this.kNames = selection.map(item => item.developmentName);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      }
    },
    handleSelectionChangeEle(selection){
      console.log(selection)
      if (selection.length > 1) {
        this.$refs.tableEle.clearSelection(); // 清空所有选择
        this.$refs.tableEle.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.eleIds = selection.map(item => item.electricId);
        this.eNames = selection.map(item => item.enterpriseName);
        this.eleContacts = selection.map(item => item.contacts);
        this.eleTeles = selection.map(item => item.telephone);
        this.kIds = selection.map(item => item.developmentId);
        this.kNames = selection.map(item => item.developManager);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      }
    },
    handleSelectionChangeEnterprise(selection) {
      if (selection.length > 1) {
        this.$refs.tableEnterprise.clearSelection();
        this.$refs.tableEnterprise.toggleRowSelection(selection.pop());
      } else {
        console.log(selection); // 查看选择的数据结构
        this.eIds = selection.map(item => item.enterpriseId);
        this.eName = selection.map(item => item.enterpriseName);
        this.eContacts = selection.map(item => item.contacts);
        this.eTeles = selection.map(item => item.telephone);
        this.yIds = selection.map(item => item.transactionId);
        this.yNames = selection.map(
          item => item.businessManagerNickName || item.businessManager
        );
        this.kIds = selection.map(item => item.developmentId);
        this.kNames = selection.map(
          item => item.developmentManagerNickName || item.developmentManager
        );
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      }
    },
    getNodeEnterprise(data, node, obj) {
      this.queryEnterpriseParams.classificationId = data.id;
      console.log(data.id);
      this.getEnterpriseList();
    },
    getNodeSeas(data, node, obj) {
      this.querySeasParams.classificationId = data.id;
      this.getSeasList();
    },
    saveSelectEnterprise() {
      if (this.eIds.toString() == "" || this.eIds.toString() == null) {
        this.$modal.msgError("请先选择客户！");
      } else {
        this.$set(this.form, "enterpriseName", this.eName.toString());
        this.$set(this.form, "enterpriseId", this.eIds.toString());
        this.$set(this.form, "contacts", this.eContacts.toString());
        this.$set(this.form, "telephone", this.eTeles.toString());
        this.$set(this.form, "transactionId", this.yIds.toString());
        this.$set(this.form, "businessManager", this.yNames.toString());
        this.$set(this.form, "businessManagerNickName", this.yNames.toString());
        this.$set(this.form, "developmentId", this.kIds.toString());
        this.$set(this.form, "developmentManager", this.kNames.toString());
        this.$set(
          this.form,
          "developmentManagerNickName",
          this.kNames.toString()
        );
        this.close();
      }
    },
    saveSelectSeas() {
      if (this.sIds.toString() == "" || this.sIds.toString() == null) {
        this.$modal.msgError("请先选择客户！");
      } else {
        this.$set(this.form, "enterpriseName", this.sName.toString());
        this.$set(this.form, "enterpriseId", this.sIds.toString());
        this.$set(this.form, "contacts", this.sContacts.toString());
        this.$set(this.form, "telephone", this.sTeles.toString());
        this.$set(this.form, "developmentId", this.kIds.toString());
        this.$set(this.form, "developmentManager", this.kNames.toString());
        this.close();
      }
    },
    saveSelectEle(){
      if (this.eleIds.toString() == "" || this.eleIds.toString() == null) {
        this.$modal.msgError("请先选择客户！");
      } else {
        this.$set(this.form, "enterpriseName", this.eNames.toString());
        this.$set(this.form, "enterpriseId", this.eleIds.toString());
        this.$set(this.form, "contacts", this.eleContacts.toString());
        this.$set(this.form, "telephone", this.eleTeles.toString());
        this.$set(this.form, "developmentId", this.kIds.toString());
        this.$set(this.form, "developmentManager", this.kNames.toString());
        this.close();
      }
    },
    handleRecordsTabClick(tab, event) {
      this.recordsActiveTab = tab.name;
    },
  },
  computed: {
    developmentManagerDisplay() {
      return (
        this.form.developmentManagerNickName || this.form.developmentManager
      );
    },
    businessManagerDisplay() {
      return this.form.businessManagerNickName || this.form.businessManager;
    },
    collaboratorDisplay() {
      return this.form.collaboratorNickName || this.form.collaboratorName;
    },
    strManagerDisplay() {
      return this.form.strNickName || this.form.strName;
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-table .el-table__header-wrapper .el-checkbox {
  display: none;
}
.teacher-form-container {
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px;
  max-width: 100%;
  max-height: 80vh;
  box-sizing: border-box;
}
::v-deep .el-dialog__header {
  padding-top: 5px;
}

.records-tabs {
  margin-bottom: 20px;
}

::v-deep .records-tabs .el-tabs__header {
  margin-bottom: 15px;
}

::v-deep .records-tabs .el-tabs__nav {
  border-radius: 4px;
}

::v-deep .records-tabs .el-tabs__item {
  height: 36px;
  line-height: 36px;
  font-weight: 500;
}

::v-deep .records-tabs .el-tabs__item.is-active {
  background-color: #409EFF;
  color: white;
  border-radius: 4px;
}

.operate-tabs {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.tab-content-scrollable {
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  padding-right: 10px;
}

::v-deep .el-tabs__content {
  overflow: visible;
  height: 100%;
}
</style>
